package com.lex.com.lex.test;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.lex.jfb.BaseActivity;
import com.lex.jfb.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2016/6/3.
 */
public class BtnTestActivity extends BaseActivity{
    private Button test_btn1;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_btn);
        findView();
        initView();
    }

    @Override
    protected void findView() {
        test_btn1 = (Button) findViewById(R.id.test_btn1);
    }

    @Override
    protected void initView() {
        test_btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countdown1();
                test_btn1.setEnabled(false);
            }
        });
    }

    private void countdown1(){
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int time = 10;
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        time--;
                        if (time<=0){
                            timer.cancel();
                            test_btn1.setText("重新发送");
                            test_btn1.setEnabled(true);
                        }else{
                            test_btn1.setText("已发送("+time+"s)");
                        }
                    }
                });
            }
        },0,1000);
    }
}
